#ifndef DATALINE_H_INCLUDED
#define DATALINE_H_INCLUDED

#include <string>
#include <map>
#include <vector>

namespace STLData{

class dataLine {
    private:
        typedef struct {
            long valueInt;
            double valueReal;
            string valueText;
            char fieldType;
        } fieldValue;
        typedef string keyType;
        map<keyType, int> hashKey;
        typedef vector<fieldValue> lineStruct;
        lineStruct lineValues;
        int maxIndex;

    private:
        int getIndex(keyType searchKey) {
            if (hashKey.find(searchKey)!= hashKey.end() ) {
                return hashKey[searchKey] ;
            } else {
                return -1;
            }
        }

    public:
        template <typename T>
        T& operator[](keyType searchKey) {
            int index;
            index = getIndex(searchKey);
            if (index != -1) {
                switch lineValues[index].fieldType
                    case 'T':
                        return lineValues[index].valueText;
                        break;
                    case 'R':
                        return lineValues[index].valueReal;
                        break;
                    case 'I':
                        return lineValues[index].valueInt;
                        break;
            } else {
                return NULL;
            }
        }

        template <typename T>
        const T& operator[](keyType searchKey) const {
            int index;
            index = getIndex(searchKey);
            if (index != -1) {
                switch lineValues[index].fieldType
                    case 'T':
                        return lineValues[index].valueText;
                        break;
                    case 'R':
                        return lineValues[index].valueReal;
                        break;
                    case 'I':
                        return lineValues[index].valueInt;
                        break;
             } else {
                return NULL;
            }
        }

        bool insert(keyType searchKey, long value);
        bool insert(keyType searchKey, double value);
        bool insert(keyType searchKey, string value);
        bool createField(keyType searchKey, char fieldType);

}

}

#endif // DATALINE_H_INCLUDED
